var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form
    ,$ = layui.jquery
    ,laydate = layui.laydate
    ,selectInput = null;
layui.use(['tableEdit', 'table', 'form', 'laydate',"selectInput"], function () {
    let layer = layui.layer //弹层
        ,table = layui.table //表格
        ,form = layui.form
        ,$ = layui.jquery
        ,laydate = layui.laydate
        ,selectInput = layui.selectInput;
    lay('.starttime').each(function(){
        laydate.render({
            elem: this
        });
    });



    layer.ready(function () {
        //获取所有供应商
        $.ajax({
            type : 'get',
            url:'customer2/getAllGys',
            dataType:"json",
            success : function (data) {
                if(data.status==200){
                    for (let i in data.data){
                        $("#supplierCode").append("<option value=\"" + data.data[i].code + "\">" + data.data[i].name + "</option>");
                    }
                    form.render('select');
                }
            },
        });

        let paymentTypeList = getdictionary(5, 17);//付款类型
        for(let i in paymentTypeList){
            $('#paymentTypeCode').append(new Option(paymentTypeList[i].name, paymentTypeList[i].code));
        }

    });

    form.on('select(supplierCode_filter)', function (data) {
        if (!isEmpty(data.value)){
            $.ajax({
                type : 'get',
                data:{supplierCode:data.value},
                url:'customer2/selectSupplierInfo',
                dataType:"json",
                async:false,
                success : function (da) {
                    if(da.status==200 ){
                        $('#paymentTypeCode').val(da.data.sourceOfCustomers);
                        $('#accountPeriod').val(da.data.accountPeriod);
                        form.render('select');
                    }
                }
            });
        }
    });

    form.on('submit(form-element)', function(data){
        $.ajax({
            type : 'get',
            data:data.field,
            url:'customer2/updateSupplierInfo',
            dataType:"json",
            async:false,
            success : function (da) {
                if(da.status==200 ){
                    layer.msg("保存成功！");
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                }
            },
            error: function(data) {
                layer.msg("保存失败!");
            }
        });
    });

    //字段是否为空或者零
    function isEmpty(obj){
        if(typeof obj == "undefined" || obj == null || obj == "" || obj == 0){
            return true;
        }else{
            return false;
        }
    }
    $("#shutdown").on("click",function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    })
})
